function closeDialogIfSucess(xhr, status, args, dialogWidget, dialogId) {
	if (args.validationFailed || args.KEEP_DIALOG_OPENED) {
		jQuery('#' + dialogId).effect("bounce", {
			times : 4,
			distance : 20
		}, 100);
	} else {
		dialogWidget.hide();
	}
}

function formatCurrency2(num) {
	num = num.toString().replace(/\$|\,/g, '');
	if (isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	if (cents < 10)
		cents = "0" + cents;
	for ( var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0, num.length - (4 * i + 3)) + ','
				+ num.substring(num.length - (4 * i + 3));
	if (num == 0)
		num = "";
	return (((sign) ? '' : '-') + '' + num);
}

function formatCurrency3(num) {
    num = isNaN(num) || num === '' || num === null ? 0.00 : num;
    return parseFloat(num).toFixed(2);
}

function formatCurrency(n, c, d, t){
	c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
	 };

function convertCurrency(txt) {
	var a = txt.value;
	if(a==null || a==''){
		return;
	}
	txt.value = formatCurrency(a, 2, ',', '.');
}

function revertCurrency(txt){
	var val = txt.value;
	if(val==null || val==''){
		return;
	}
	val = val.toString().replace(/\./g,'');
	val = val.toString().replace(',', '.');
	txt.value = val;
}

function isNumeric(eventObj){
    var keyCode;
 
    if(eventObj.keyCode) //For IE
        keyCode = eventObj.keyCode;
    else if(eventObj.Which)
        keyCode = eventObj.Which;  // For FireFox
    else
        keyCode = eventObj.charCode; // Other Browser
 
    if ( keyCode!=8 && keyCode!=9 && keyCode!=13 && !(keyCode>=35 && keyCode<=40) && keyCode!=46)
    {
        if (keyCode < 44 || keyCode > 57 || keyCode==45 || keyCode==47) //if not a number
            return false; // disable key press
        else{
        	return true; // enable key press
        }
     }        
 }

function isNumericForNpwp(eventObj){
    var keyCode;
 
    if(eventObj.keyCode) //For IE
        keyCode = eventObj.keyCode;
    else if(eventObj.Which)
        keyCode = eventObj.Which;  // For FireFox
    else
        keyCode = eventObj.charCode; // Other Browser
 
    if ( keyCode!=8 && keyCode!=9 && keyCode!=13 && !(keyCode>=35 && keyCode<=40) && keyCode!=46)
    {
        if (keyCode < 45 || keyCode > 57 || keyCode==47) //if not a number
            return false; // disable key press
        else{
        	return true; // enable key press
        }
     }
 }




function isValidNum(form){
    var regex = /^\d{2}(\.\d)?$/;
    var num = form.value;
    if(regex.test(num)) {
        return true;
    } else {
        return false;
    }
}
